home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / obj2asm.zip / O.H next >
Text File  |  1991-10-02  |  18KB  |  476 lines

  1. typedef unsigned char uchar;
  2. typedef unsigned int word;
  3. typedef unsigned long int dword;
  4. typedef signed long int dint;
  5.  
  6. #define FALSE   (0==1)
  7. #define TRUE    (!FALSE)
  8. #define FULL    (EOF-1)
  9.  
  10. #define L_SET   0                       /* Seek methods for fseek() */
  11. #define L_REL   1
  12. #define L_APND  2
  13.  
  14. /*
  15. ** Definitions for AVL balanced, threaded tree structures
  16. */
  17. #define LEFT        0                   /* Left pointer is array element 0  */
  18. #define RIGHT       1                   /* Right ptr is array element 1     */
  19. #define BALANCED    2                   /* Balanced is not right nor left   */
  20. #define EQUAL       2                   /* Value returned for equal compare */
  21.  
  22. #define NAMESIZE    40                  /* Max Size of Labels */
  23. #define OPSIZE      60                  /* Max Size of Operand Text */
  24. #define COMSIZE     81                  /* Max Size of Hex Comment */
  25.  
  26. #define UNKNOWN     0                   /* Symbol 'type' values */
  27. #define NEAR        1                   /* Symbol is a NEAR label        */
  28. #define FAR         2                   /* Symbol is a FAR label         */
  29. #define BYTE_PTR    3                   /* Symbol is a   1 byte quantity */
  30. #define WORD_PTR    4                   /* Symbol is a   2 byte quantity */
  31. #define DWORD_PTR   5                   /* Symbol is a   4 byte quantity */
  32. #define FWORD_PTR   6                   /* Symbol is a   6 byte quantity */
  33. #define QWORD_PTR   7                   /* Symbol is an  8 byte quantity */
  34. #define TBYTE_PTR   8                   /* Symbol is a  10 byte quantity */
  35.  
  36. #define LOCAL       0                   /* Symbol 'domain' values */
  37. #define PUBLIC      1
  38.  
  39. #define ENUMERATED  0                   /* Data record 'type' values */
  40. #define ITERATED    1
  41.  
  42. #define LOBYTE  0                       /* Fix-up record forms */
  43. #define OFFSET  1
  44. #define BASE    2
  45. #define POINTER 3
  46. #define HIBYTE  4
  47. #define LOADOFF 5
  48.  
  49. #define SEGMENT     0
  50. #define GROUP       1
  51. #define EXTERNAL    2
  52. #define FRAME       3
  53. #define LOCATION    4
  54. #define TARGET      5
  55. #define NONE        6
  56.  
  57.  
  58. #define NORMAL  0                       /* data_check() return values */
  59. #define LABEL   1
  60. #define FIXUP   2
  61. #define BAD     3                       /* Half aligned */
  62.  
  63. #define REGULAR 0                       /* Regular Intel OMF record types    */
  64. #define LARGER  1                       /* Extended for > 64k segments by MS */
  65.  
  66. #define EXT_PER_REC     64              /* Easy number of EXT's per segment */
  67.  
  68. #define NREG    0                       /* Shorthand register notations */
  69. #define AL      1
  70. #define CL      2
  71. #define DL      3
  72. #define BL      4
  73. #define AH      5
  74. #define CH      6
  75. #define DH      7
  76. #define BH      8
  77.  
  78. #define AX      9                       /* Or EAX, etc. as may arise */
  79. #define CX      10
  80. #define DX      11
  81. #define BX      12
  82. #define SP      13
  83. #define BP      14
  84. #define SI      15
  85. #define DI      16
  86.  
  87. #define ES      17                      /* Segment register identifiers */
  88. #define CS      18
  89. #define SS      19
  90. #define DS      20
  91. #define FS      21
  92. #define GS      22
  93.  
  94. #define MAX_SEG_REGS    6
  95.  
  96.  
  97. typedef struct node_s NODE_T;
  98. struct node_s {                         /*--- Structure of a tree node ---*/
  99.     short   balance;                    /* Balance of this tree node      */
  100.     NODE_T  *ptr[2];                    /* Left & Right pointers          */
  101.     int     thread[2];                  /* Indicates thread or pointer    */
  102.     void    *data;
  103. };
  104.  
  105.  
  106. struct name_s {                         /*--- Structure of NAME list ---*/
  107.     int     index;                      /* Sequentially assigned number */
  108.     char    name[NAMESIZE+1];           /* Name from LNAMES record      */
  109. };
  110. typedef struct name_s NAME_T;
  111.  
  112.  
  113. struct seg_s {                              /*--- Structure of SEGMENT list --*/
  114.     int             index;                  /* Sequentially assigned no.      */
  115.     int             name;                   /* Name index for segment name    */
  116.     NAME_T          *class;                 /* Pointer to Name for seg. class */
  117.     word            length;                 /* Length of segment (incl. dups) */
  118.     int             code;                   /* Flag indicating code segment   */
  119.     int             bit32;                  /* 32 bit segment                 */
  120.     int             new_mode[MAX_SEG_REGS]; /* Frame Mode                     */
  121.     int             new_index[MAX_SEG_REGS];/* Frame Index                    */
  122.     int             prv_mode[MAX_SEG_REGS]; /* Frame Mode                     */
  123.     int             prv_index[MAX_SEG_REGS];/* Frame Index                    */
  124. };
  125. typedef struct seg_s SEG_T;
  126.  
  127.  
  128. struct grp_s {                          /*---- Structure of GROUP list ----*/
  129.     int     index;                      /* Sequentially assigned number    */
  130.     int     name;                       /* Name index for group name       */
  131. };
  132. typedef struct grp_s GRP_T;
  133.  
  134.  
  135. struct struc_s {                        /*- Structure of STRUC definitions -*/
  136.     char            *form;              /* Form of structure                */
  137.     int             index;              /* Structure number                 */
  138. };
  139. typedef struct struc_s STRUC_T;
  140.  
  141.  
  142. struct pub_s {                          /*--- Structure of PUBLICS list ---*/
  143.     int             seg_idx;            /* Publics are kept in segment     */
  144.     dword   offset;             /*   index and offset order        */
  145.     char            name[NAMESIZE];     /* Name from PUBDEF record         */
  146.     int             type;               /* UNKNOWN,NEAR,FAR,BYTE_PTR,...   */
  147.     int             domain;             /* 0 = Local, 1 = Public           */
  148.     int             scope;              /* TRUE = public, FALSE = local    */
  149.     STRUC_T         *structure;         /* Label before a dup struc record */
  150. };
  151. typedef struct pub_s PUB_T;
  152.  
  153.  
  154. struct ext_s {                          /*-- Structure of EXTERNALS list --*/
  155.     int             index;              /* Sequentially assigned number    */
  156.     char            name[NAMESIZE];     /* Name from EXTDEF record         */
  157.     int             type;               /* UNKNOWN,NEAR,FAR,BYTE_PTR,...   */
  158.     int             pos_abs;            /* TRUE = Could be ABS, FALSE = no */
  159.     int             com_ext;            /* 0 = EXTRN, 1 = COMM             */
  160.     int             var_type;           /* Number from COMDEF record       */
  161.     dword   size;               /* Number of Bytes (For COMMUNAL)  */
  162.     int             used;               /* Ever accessed?                  */
  163.     int             scope;              /* TRUE = public, FALSE = local    */
  164. };
  165. typedef struct ext_s EXT_T;
  166.  
  167.  
  168.  
  169. struct sex_s {                          /*-- Segment/External usage record --*/
  170.     int     seg_index;                  /* Segment being used in             */
  171.     EXT_T   *ext_rec;                   /* External being used               */
  172. };
  173. typedef struct sex_s SEX_T;
  174.  
  175.  
  176. struct dat_s {                          /*- Structure of DATA records list -*/
  177.     int             seg_idx;            /* Data records are kept in         */
  178.     dword   offset;             /*   segment index and offset order */
  179.     int             type;               /* 0 = Enumerated, 1 = Iterated     */
  180.     int             size;               /* Size of data (db,dw,dq, etc.)    */
  181.     long            file_pos;           /* Position stored in .OBJ file     */
  182.     int             length;             /* Length in bytes of .OBJ data     */
  183.     int             extended;           /* 386 type record                  */
  184.     STRUC_T         *structure;         /* Structure for some DUP records   */
  185. };
  186. typedef struct dat_s DAT_T;
  187.  
  188.  
  189. struct fix_s {                          /*- Structure for a FIXUPP record -*/
  190.     int             seg_idx;            /* Fixups are kept in segment      */
  191.     dword           dat_offset;         /*   index, data offset, and       */
  192.     int             offset;             /*   offset order                  */
  193.     int             relate;             /* Self / Segment Relative         */
  194.     int             form;               /* hibyte/lobyte/base/offset/ptr...*/
  195.     int             a_mode;             /* Mode of Frame                   */
  196.     int             a_index;            /* Index of Frame                  */
  197.     int             b_mode;             /* Mode of Target                  */
  198.     int             b_index;            /* Index of Target                 */
  199.     long            displacement;       /* Added to Result of Frame:Target */
  200.     int             extended;           /* 386 type fixup?                 */
  201.     int             word_sized;         /* BASE/OFFSET/LOADOFF             */
  202. };
  203. typedef struct fix_s FIX_T;
  204.  
  205.  
  206. struct thread_s {
  207.     int     mode;
  208.     int     index;
  209. };
  210. typedef struct thread_s THREAD_T;
  211.  
  212.  
  213. struct fixer_s {
  214.     int     num_bytes;
  215.     char    *form;
  216.     char    *prefix;
  217. };
  218. typedef struct fixer_s FIXER_T;
  219.  
  220.  
  221. struct hint_s {
  222.     int             seg_idx;    /* Segment for processing           */
  223.     int             hint_type;  /* 0=Code,1=Data(DB)                */
  224.     dword   offset;     /* Starting position within segment */
  225.     dword   length;     /* Length of hint                   */
  226. };
  227. typedef struct hint_s HINT_T;
  228.  
  229.  
  230. struct inst_s {                                     /*-- Instruction Table --*/
  231.     int     (*rtn)( uchar, char *, int );   /* Rtn to process byte   */
  232.     int     special;                                /* Data to pass to rtnn  */
  233.     char    *text;                                  /* Data to pass to rtn   */
  234. };
  235. typedef struct inst_s INST_T;
  236.  
  237.  
  238. typedef struct {
  239.   dint hex_offset;
  240.   word line_number;
  241. } LINE_T;    /* Used for storing line numbers */
  242.  
  243.  
  244. typedef struct __local_var {
  245.   word class;           /* variable class */
  246.   char bInfo1;
  247.   char bInfo2;
  248.   word wInfo1;
  249.   char vname[33];       /* variable name */
  250.   struct __local_var *next;
  251. } LOCAL_VAR;
  252.  
  253. typedef enum {
  254.   VT_VAR,
  255.   VT_ARG
  256. } VTYPE;
  257.  
  258. typedef struct {
  259.   dint hex_offset;  /* beginning at this offset in file */
  260.   LOCAL_VAR *head;   /* pointer to list of lcoals */
  261. } SCOPE_T;
  262.  
  263. #define EDATA   0                       /* Enumerated data type */
  264. #define IDATA   1                       /* Iterated data type */
  265.  
  266. extern FILE     *o_file;                /* Input file (.OBJ) */
  267. extern long     o_position;             /* Position in file of current data */
  268.  
  269. extern NODE_T   *line_tree;             /* line numbers        */
  270. extern NODE_T   *loc_scope_tree;        /* scope for locals    */
  271. extern NODE_T   *arg_scope_tree;        /* scope for arguments */
  272. extern NODE_T   *end_scope_tree;        /* end of scope        */
  273.  
  274. extern NODE_T   *name_tree;             /* Names by index */
  275. extern NODE_T   *segment_tree;          /* Segments by index */
  276. extern NODE_T   *public_tree;           /* Public values by segment/offset */
  277. extern NODE_T   *extern_tree;           /* Externals by index */
  278. extern NODE_T   *sex_tree;              /* External usage by segment */
  279. extern NODE_T   *data_tree;             /* Data records by segment/offset */
  280. extern NODE_T   *struc_tree;            /* Tree of structures */
  281. extern NODE_T   *fix_tree;              /* Fix up records by segment/offset */
  282. extern NODE_T   *hint_tree;             /* Dis-assembly hints */
  283. extern NODE_T   *group_tree;            /* Not Used */
  284. extern NODE_T   *type_tree;             /* Not Used */
  285. extern NODE_T   *block_tree;            /* Not Used */
  286.  
  287. extern SEG_T    *seg_rec;
  288. extern NODE_T   *pub_node;              /* Next node of public symbol in list */
  289. extern PUB_T    *pub_rec;               /* Next public symbol in list */
  290. extern PUB_T    *last_pub_rec;          /* Last public symbol encountered */
  291. extern NODE_T   *fix_node;              /* Next node of fixup in list */
  292. extern FIX_T    *fix_rec;               /* Next fixup in list */
  293. extern NODE_T   *hint_node;             /* Next node of hint in list */
  294. extern HINT_T   *hint_rec;              /* Next hint in list */
  295.  
  296. extern SEG_T    seg_search;
  297. extern GRP_T    grp_search;
  298. extern PUB_T    pub_search;
  299. extern FIX_T    fix_search;
  300. extern NAME_T   name_search;
  301. extern HINT_T   hint_search;
  302.  
  303. extern int      label_count;
  304.  
  305. extern word code_string;        /* Stringizing Limit in Code */
  306. extern word data_string;        /* Stringizing Limit in Data */
  307.  
  308. extern FIXER_T  fix_type[];             /* Fixup types                     */
  309. extern INST_T   instr[];                /* Dis-assembly routine table      */
  310. extern INST_T   ex_instr[];             /* Extra [0F] Dis-assembly rtn tbl */
  311. extern char     *esc_inst[];            /* Floating Point opcode table     */
  312. extern char     *op_grp[][8];           /* Special Groups of instructions  */
  313.  
  314. extern int  pass;                               /* Pass number for process() */
  315. extern int  processor_type_comment_occurred;    /* COMENT record occurred? */
  316.  
  317. extern int              segment;            /* Segment being "process()'d" */
  318. extern dword    inst_offset;        /* Address being "process()'d" */
  319. extern int              processor_mode;     /* 86,286,386,etc              */
  320. extern int              segment_mode;       /* processor mode for curr seg */
  321. extern int              segment_bytes;      /* Segment WORD size           */
  322.  
  323. extern char     *cseg_name;         /* Code segment name             */
  324. extern char     *dseg_name;         /* Data segment name             */
  325. extern PUB_T    *start_pub;         /* Starting addr public          */
  326. extern int      hex_finish;         /* Finish hex comment?           */
  327. extern int      tab_offset;         /* Current output tab stop       */
  328. extern int      compatibility;      /* Output type                   */
  329. extern int      add_labels;         /* Invent new labels?            */
  330. extern int      hex_output;         /* Hex output in comments?       */
  331. extern int      over_seg;           /* -1 = No overiding segment yet */
  332.  
  333. int scope_compare( SCOPE_T*, SCOPE_T* );
  334. int linnum_compare( LINE_T *, LINE_T * );
  335. int name_compare( NAME_T *, NAME_T * );
  336. int pub_compare( PUB_T *, PUB_T * );
  337. int seg_compare( SEG_T *, SEG_T * );
  338. int grp_compare( GRP_T *, GRP_T * );
  339. int fix_compare( FIX_T *, FIX_T * );
  340. int dat_compare( DAT_T *, DAT_T * );
  341. int ext_compare( EXT_T *, EXT_T * );
  342. int struc_compare( STRUC_T *, STRUC_T * );
  343. int hint_compare( HINT_T *, HINT_T * );
  344.  
  345. NODE_T *pub_insert( int, dword, char *, int, int );
  346. void sex_insert( int, EXT_T * );
  347. void ext_insert( char *, int, int, dword, word, int );
  348. void dat_insert( int, dword, long, int, int, int );
  349. STRUC_T *struc_insert( char * );
  350.  
  351. void theadr( void );
  352. void lnames( word );
  353. void grpdef( word );
  354. void segdef( void );
  355. void pubdef( word, int );
  356. void extdef( word, int );
  357. void ledata( word, int );
  358. void lidata( word, int );
  359. void linnum( word);
  360. void fixupp( word, int );
  361. void coment( word );
  362. void comdef( word, int );
  363. void modend( word, int );
  364. void typdef( word );
  365. void pubrpt( void );
  366. void extrpt( void );
  367.  
  368. void print_ext( EXT_T * );
  369. void list_ext( void );
  370. void list_pub( void );
  371. void list_struc( void );
  372. void list_fix( void );
  373.  
  374. void process( void );
  375.  
  376. void load_extra( char *, char * );
  377.  
  378. void init_trees( void );
  379.  
  380. int size_to_type( int );
  381. int reg_size_to_type( int );
  382. int type_to_size( int );
  383. char *type_to_text( int );
  384. char *size_to_opcode( int, int * );
  385.  
  386. uchar get_byte( void );
  387. int get_int( void );
  388. word get_word( void );
  389. dword get_long( void );
  390. void get_str( int, char * );
  391. int get_name( char * );
  392. int get_index( int * );
  393.  
  394. void empty_string( int );
  395.  
  396. int buff_init( int );
  397. int buff_add( int );
  398. void buff_reseek( void );
  399. void buff_empty( void );
  400. int buff_getc( void );
  401. int buff_regetc( void );
  402.  
  403. void out_label( char * );
  404. void out_labelc( char * );
  405. void out_opcode( char * );
  406. void out_operand( char * );
  407. void out_comment( char * );
  408. void out_endline( void );
  409. void out_newline( void );
  410. void out_directive( char * );
  411. void out_line( char *, char *, char *, char * );
  412. char *out_hexize( dword, char *, int );
  413.  
  414. void fmt_error( char * );
  415.  
  416. NODE_T *new_tree( void *, int );
  417. NODE_T *start( NODE_T *, int );
  418. NODE_T *traverse( NODE_T *, int );
  419. NODE_T *insert( void *, NODE_T *, int(*)(void *, void *) );
  420. void *find( void *, NODE_T *, int(*)(), NODE_T ** );
  421. char *search( char *, NODE_T *, int(*)() );
  422. void *o_malloc( word );
  423. void tab_seek( int );
  424.  
  425. int find_member( char *, STRUC_T *, long * );
  426. PUB_T *check_public( int, int, long, char );
  427. void get_target( char *, FIX_T *, int, long, int, int, int, int *, int );
  428. int get_fix( char *, int, int, int, int, int, int *, int );
  429. char *mode_name( int, int );
  430. void adjust_assumes( void );
  431. void abort_assumes( void );
  432.  
  433. void fix_advance( void );
  434.  
  435. int decode_fixup( int, int, int, int, int );
  436.  
  437. int data_check( word );
  438. void esc_special( char *, char *, int, int );
  439.  
  440. void inst_init    ( void );
  441.  
  442. int stub         ( uchar, char *, int );
  443.  
  444. int one_byte     ( uchar, char *, int );
  445. int two_byte     ( uchar, char *, int );
  446. int two_ubyte    ( uchar, char *, int );
  447. int three_byte   ( uchar, char *, int );
  448. int five_byte    ( uchar, char *, int );
  449.  
  450. int one_a        ( uchar, char *, int );
  451. int two_a        ( uchar, char *, int );
  452. int three_a      ( uchar, char *, int );
  453.  
  454. int in_out       ( uchar, char *, int );
  455. int string_byte  ( uchar, char *, int );
  456. int enter        ( uchar, char *, int );
  457. int two_bcd      ( uchar, char *, int );
  458.  
  459. int disp8        ( uchar, char *, int );
  460. int disp16       ( uchar, char *, int );
  461.  
  462. int wait         ( uchar, char *, int );
  463. int prefix       ( uchar, char *, int );
  464. int seg_over     ( uchar, char *, int );
  465.  
  466. int opsize_over  ( uchar, char *, int );
  467. int adrsize_over ( uchar, char *, int );
  468.  
  469. int mod_reg      ( uchar, char *, int );
  470.  
  471. int esc          ( uchar, char *, int );
  472. int extra        ( uchar, char *, int );
  473.  
  474.  
  475. #define TC (int(*)(void*,void*)) /* *; */
  476.